/*
 *  Copyright 2007 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.core;

/**
 * <p>Represents element of {@link Sequence}.</p>
 * <p><a href="SequenceItem.java.html"><i>View Source</i></a>
 * </p>
 * <p/>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version : $Revision: 1.3 $ : 2007/12/17 13:38:25 $
 * @see com.blandware.atleap.model.core.Sequence
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.class table="`al_core_sequence_item`" lazy="false" dynamic-update="true" dynamic-insert="true"
 * @hibernate.cache usage="read-write"
 */
public class SequenceItem extends BaseObject {
	//~ Instance fields ========================================================

    /**
     * The ID of this sequence item
     */
	protected Long id;
    /**
     * Sequence to which this sequence item belong
     */
	protected Sequence sequence;
    /**
     * Page to which this item points
     */
    protected Page page = null;
    /**
     * Content resource to which this item points
     */
    protected ContentResource contentResource = null;
    /**
     * Position of this item inside its sequence
     */
    protected Integer position;
    /**
     * Version of this sequence item (used in optimistic locking)
     */
	protected Long version;

	//~ Methods ================================================================
	/**
	 * Returns the id of this sequence item.
	 *
	 * @return the id
	 * @struts.form-field
	 * @hibernate.id column="`id`"
	 * generator-class="increment" unsaved-value="null"
	 */
	public Long getId() {
		return id;
	}

    /**
     * Sets the id of this sequence item.
     *
     * @param id new id
     */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Returns the sequence to which this sequence item belongs.
	 *
	 * @return a sequence
     * @struts.form-field
	 * @hibernate.many-to-one column="`sequence_id`" not-null="false" outer-join="false" lazy="true"
	 */
	public Sequence getSequence() {
		return sequence;
	}

    /**
     * Sets the sequence to which this sequence item belongs.
     *
     * @param sequence new master sequence
     */
	public void setSequence(Sequence sequence) {
		this.sequence = sequence;
	}

    /**
     * Just a method to allow form method to be created.
     *
     * @return null
     * @struts.form-field
	 * @struts.validator type="required"
	 * @struts.validator-args arg0resource="core.sequenceItem.form.object"
	 */
    protected String getObjectIdentifier() {
        return null;
    }

    /**
     * Returns the page to which this item points.
     *
     * @return the page
     * @struts.form-field
     * @hibernate.many-to-one column="`page_id`" not-null="false" outer-join="false" lazy="false"
     */
    public Page getPage() {
        return page;
    }

    /**
     * Sets the page to which this item points.
     *
     * @param page page to set
     */
    public void setPage(Page page) {
        this.page = page;
    }

    /**
     * Returns the content resource to which this item points.
     *
     * @return the content resource
     * @struts.form-field
     * @hibernate.many-to-one column="`resource_id`" not-null="false" outer-join="false" lazy="false"
     */
    public ContentResource getContentResource() {
        return contentResource;
    }

    /**
     * Sets the content resource to which this item points.
     *
     * @param contentResource content resource to set
     */
    public void setContentResource(ContentResource contentResource) {
        this.contentResource = contentResource;
    }

    /**
     * Returns sequence item position.
     *
     * @return position
     * @hibernate.property
	 * @hibernate.column name="`pos`" not-null="true" unique="false"
     */
    public Integer getPosition() {
        return position;
    }

    /**
     * Sets sequence item position.
     *
     * @param position position to set
     */
    public void setPosition(Integer position) {
        this.position = position;
    }

    /**
     * Returns version of this sequence item.
     *
	 * @return the version
	 * @struts.form-field
	 * @hibernate.version column="`version`" type="long" unsaved-value="null"
	 */
	public Long getVersion() {
		return version;
	}

    /**
     * Sets version of this sequence item.
     *
     * @param version new version
     */
	public void setVersion(Long version) {
		this.version = version;
	}

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SequenceItem that = (SequenceItem) o;

        if (position != null ? !position.equals(that.position) : that.position != null)
            return false;
        if (sequence != null ? !sequence.equals(that.sequence) : that.sequence != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (sequence != null ? sequence.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);
        return result;
    }
}